package com.qbw.app.model;

import androidx.databinding.Bindable;

import com.google.gson.Gson;
import com.qbw.app.BR;
import com.qbw.l.L;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author QBW
 * @date 2019-09-02
 */
public class Warning extends BaseModel implements Serializable {

    public static final int NOTIFICATION_TYPE_SAFE = 1;
    public static final int NOTIFICATION_TYPE_VEHICLE_STATUS = 2;
    public static final int QUERY_TYPE_EVENT = 1;
    public static final int QUERY_TYPE_ELECTRIC_AREA = 2;
    public static final int READ_STATE_ALREADY = 1;
    public static final int READ_STATE_UNREAD = 0;

    private long alarmId;
    private String alarmName;
    private int alarmType;
    private String startLatitude;
    private String startLocation;
    private String startLongitude;
    private long startTime;
    private String travelCode;
    private int appSwitch;
    private String vehicleCode;
    private int alarmState;
    private String alarmStateName;
    /**
     * 类型 1事件 2围栏
     */
    private int queryType;
    private String fenceJson;
    /**
     * 1 ：已读 0：未读
     */
    private int read;
    private String vehicleNickName;

    private String travelName;
    private long logTime; // 记录时间

    public int getAlarmState() {
        return alarmState;
    }

    public void setAlarmState(int alarmState) {
        this.alarmState = alarmState;
    }

    public String getAlarmStateName() {
        return alarmStateName;
    }

    public void setAlarmStateName(String alarmStateName) {
        this.alarmStateName = alarmStateName;
    }

    @Bindable
    public long getAlarmId() {
        return alarmId;
    }

    public void setAlarmId(long alarmId) {
        this.alarmId = alarmId;
    }

    @Bindable
    public String getAlarmName() {
        return alarmName;
    }

    public void setAlarmName(String alarmName) {
        this.alarmName = alarmName;
    }

    @Bindable
    public int getAlarmType() {
        return alarmType;
    }

    public void setAlarmType(int alarmType) {
        this.alarmType = alarmType;
    }

    public String getStartLatitude() {
        return startLatitude;
    }

    public void setStartLatitude(String startLatitude) {
        this.startLatitude = startLatitude;
    }

    public String getStartLocation() {
        return startLocation;
    }

    public void setStartLocation(String startLocation) {
        this.startLocation = startLocation;
    }

    public String getStartLongitude() {
        return startLongitude;
    }

    @Bindable
    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public String getTravelCode() {
        return travelCode;
    }

    public void setTravelCode(String travelCode) {
        this.travelCode = travelCode;
    }

    @Bindable
    public int getAppSwitch() { return appSwitch;}

    public void setAppSwitch(int appSwitch) {
        this.appSwitch = appSwitch;
        notifyPropertyChanged(com.qbw.app.BR.appSwitch);
    }

    public String getVehicleCode() {
        return vehicleCode;
    }

    public void setVehicleCode(String vehicleCode) {
        this.vehicleCode = vehicleCode;
    }

    public int getQueryType() {
        return queryType;
    }

    public String getFenceJson() {
        return fenceJson;
    }

    @Bindable
    public int getRead() {
        return read;
    }

    public void setRead(int read) {
        this.read = read;
        notifyPropertyChanged(BR.read);
    }

    public String getVehicleNickName() {
        return vehicleNickName;
    }

    public void setVehicleNickName(String vehicleNickName) {
        this.vehicleNickName = vehicleNickName;
    }

    public ElectricArea.InfoList getFenceJsonModel() {
        try {
            return new Gson().fromJson(fenceJson, ElectricArea.InfoList.class);
        } catch (Exception e) {
            e.printStackTrace();
            L.GL.e(e);
        }
        return null;
    }

    public void setStartLongitude(String startLongitude) {
        this.startLongitude = startLongitude;
    }

    public void setQueryType(int queryType) {
        this.queryType = queryType;
    }

    public void setFenceJson(String fenceJson) {
        this.fenceJson = fenceJson;
    }

    public String getTravelName() {
        return travelName;
    }

    public void setTravelName(String travelName) {
        this.travelName = travelName;
    }

    public long getLogTime() {
        return logTime;
    }

    public void setLogTime(long logTime) {
        this.logTime = logTime;
    }

    public static class ElectricArea extends BaseModel implements Serializable {
        private double longitude;
        private double latitude;
        private double radius;
        private long fenceId;
        private String fenceName;

        public double getLongitude() {
            return longitude;
        }

        public double getLatitude() {
            return latitude;
        }

        public double getRadius() {
            return radius;
        }

        public long getFenceId() {
            return fenceId;
        }

        public String getFenceName() {
            return fenceName;
        }

        public static class InfoList extends BaseModelList<ElectricArea> implements Serializable {

        }
    }

    public static class Data extends BaseModelList<Warning> {

        public Data() {
        }

        public Data(List<Warning> list) {
            super(list);
        }
    }

    public static class Response extends BaseResponse<Data> {}

    public static class ResponseList extends BaseResponseList<Warning> {

        public List<String> getAlarmIdList() {
            if (size() <= 0) {
                return new ArrayList<>();
            }
            List<String> idList = new ArrayList<>();
            for (Warning w : getData()) {
                idList.add(String.valueOf(w.getAlarmId()));
            }
            return idList;
        }

    }

    public static class Box extends BaseModel {
        private String title;
        private Data list;

        public Box(String title, Data list) {
            this.title = title;
            this.list = list;
        }

        public String getTitle() {
            return title;
        }

        public Data getList() {
            return list;
        }
    }

    public static class HomeInfo extends BaseModel {

        private Warning alarmInfo;
        private int unRead;

        public Warning getAlarmInfo() {
            return alarmInfo;
        }

        @Bindable
        public int getUnRead() {
            return unRead;
        }
    }
}
